// webpack plugins
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.config.common.js');
var path = require("path");
var CompressionPlugin = require("compression-webpack-plugin");
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var webpack = require("webpack");



/**
 * config
 * Reference: http://webpack.github.io/docs/configuration.html
 */
module.exports = webpackMerge(commonConfig, {
  module: {
    rules: [{
        test: /\.ts$/,
        include: path.resolve(__dirname, './src'),
        loader: 'string-replace-loader',
        options: {
          multiple: [{
            search: 'test\.58caimi\.com',
            replace: 'hrhg.integrity.com.cn',
            flags: 'ig'
          }, {
            search: 'www\.58caimi\.com',
            replace: 'hrhg.integrity.com.cn',
            flags: 'ig'
          }, {
            search: 'ogvk6eo7a\.bkt\.clouddn\.com',
            replace: 'images.integrity.com.cn',
            flags: 'ig'
          }]
        },
        enforce: "pre"
      },
      {
        test: /\.js$/,
        loader: 'string-replace-loader',
        options: {
          search: '\\"\\/static/',
          replace: '"static',
          flags: 'ig'
        },
        enforce: "post"
      },
      {
        test: /\.json$/,
        include: path.resolve(__dirname, './src'),
        use: [
          "json-loader",
          {
            loader: 'string-replace-loader',
            options: {
              multiple: [{
                search: 'test\.58caimi\.com',
                replace: 'hrhg.integrity.com.cn',
                flags: 'ig'
              }, {
                search: 'www\.58caimi\.com',
                replace: 'hrhg.integrity.com.cn',
                flags: 'ig'
              }, {
                search: 'ogvk6eo7a\.bkt\.clouddn\.com',
                replace: 'images.integrity.com.cn',
                flags: 'ig'
              }]
            }
          }
        ],
        enforce: "pre"
      },
    ]
  },
  devtool: 'source-map',
  devServer: {
    inline: true,
    hot: true,
    historyApiFallback: true
  },
  output: {
    path: path.resolve(__dirname),
    publicPath: '',
    filename: '[name].js',
    chunkFilename: '[id].chunk.js'
  },
  target: 'electron-renderer',
  plugins: [
    new ExtractTextPlugin('styles/[name].css'),
    new CopyWebpackPlugin([{
      from: 'src/read-article.html',
      to: ''
    }, {
      from: 'src/client.html',
      to: ''
    }]),
    new webpack.DefinePlugin({
      BUILD_IN_PRODUCTION: JSON.stringify(false)
    }),
  ]
});